package com.match.competition_sub.service.impl;

import com.alibaba.excel.EasyExcel;
import com.match.competition_sub.entity.Teacher;
import com.match.competition_sub.excel.TeacherData;
import com.match.competition_sub.listener.TeacherExcelListener;
import com.match.competition_sub.mapper.TeacherMapper;
import com.match.competition_sub.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AdiosF
 * @since 2021-09-21
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    /**
     * 通过Excel录入教师信息
     * @param file
     * @param teacherService
     */
    @Override
    public void addTeaByExcel(MultipartFile file, TeacherService teacherService) {
        try{
            //文件输入流
            InputStream in=file.getInputStream();
            //调用方法进行读取
            EasyExcel.read(in, TeacherData.class,new TeacherExcelListener(teacherService)).sheet().doRead();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 获得用户角色名称
     * @param roleId
     * @return
     */
    @Override
    public String getRoleName(String roleId) {
        String roleName=baseMapper.getRoleNameByRoleId(roleId);
        return roleName;
    }

    /**
     * 移除中间表信息
     * @param number
     */
    @Override
    public void removeUserAndRoleByNumber(String number) {
        baseMapper.removeUserAndRole(number);
    }


    //获取角色ID
    @Override
    public String getRoleIdByName(String roleName) {
        String roleId=baseMapper.getRoleIdByRoleName(roleName);
        return roleId;
    }


    /**
     * 修改申请表中教师的姓名信息
     * @param number
     * @param teacherName
     */
    @Override
    public void updateCompetitionInfoTeacherName(String teacherName,String number) {
        baseMapper.updateCompetitionInfoTeacherName(teacherName,number);
    }
}
